home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / test / testmain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  1.7 KB  |  84 lines

  1. /* ----------------------------------------------------------------
  2.  * MAIN PROGRAM FOR TESTING PURPOSES
  3.  *
  4.  * NOTE: this program should be linked with all postgres modules (except
  5.  * MAIN.o) because it uses routines not defined in cinterface.a
  6.  *
  7.  * It does some initializing and then calls TestMain().
  8.  * (this is your routine!)
  9.  *
  10.  * Almost all the arguments are passed to TestMain (so you can define
  11.  * and use your own command liner options).
  12.  *
  13.  * The only such options used by this routine are:
  14.  *     "-db <data_base_name>"
  15.  *
  16.  * Have fun!
  17.  *
  18.  * $Header: /private/postgres/src/test/RCS/testmain.c,v 1.2 1990/11/19 15:04:25 sp Exp $
  19.  * ----------------------------------------------------------------
  20.  */
  21.  
  22. #include <stdio.h>
  23. #include <strings.h>
  24. #include <signal.h>
  25. #include <tcop/tcop.h>
  26.  
  27. void    TestMain();
  28.  
  29. extern char *DBName;
  30.  
  31. main(argc, argv)
  32. int    argc;
  33. char    *argv[];
  34. {
  35.     char        *datname;
  36.     extern    jmp_buf    Warn_restart;
  37.     int        geteuid(), setuid();            /* uid_t */
  38.     int        chdir(), setjmp(), fprintf();
  39.     char        *getenv();
  40.     extern        exitpg();
  41.     extern        resetmmgr();
  42.     int        i;
  43.  
  44.     datname = NULL;
  45.     for (i=1; i<argc; i++) {
  46.         if (!strcmp(argv[i], "-db")) {
  47.         i++;
  48.         if (i >= argc) {
  49.             fprintf(stderr,
  50.             "Error: '-db' must be followed by a database name\n");
  51.             exitpg(1);
  52.         }
  53.         datname = argv[i];
  54.         }
  55.     }
  56.  
  57.     if (datname == NULL) {
  58.         datname = getenv("USER");
  59.         if (datname == (char *)NULL) {
  60.         fprintf(stderr, "failed getenv(\"USER\")");
  61.         exitpg(1);
  62.         }
  63.     }
  64.  
  65.     signal(SIGHUP, die);
  66.     signal(SIGINT, die);
  67.     signal(SIGTERM, die);
  68.  
  69.     DBName = datname;
  70.     InitPostgres(datname);
  71.  
  72.     setuid(geteuid());
  73.     signal(SIGHUP, handle_warn);
  74.  
  75.     if (setjmp(Warn_restart) != NULL) {
  76.         AbortCurrentTransaction();
  77.     }
  78.  
  79.     TestMain(argc, argv);
  80.  
  81.     exitpg(0);
  82. }
  83.  
  84.